package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.db.Notification;
import com.itheima.domain.db.Question;
import com.itheima.domain.db.User;
import com.itheima.service.db.NotificationService;
import com.itheima.service.db.QuestionService;
import com.itheima.vo.SettingVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zsk
 * @create 2022-03-22-21:22
 */
@Component
public class SettingManager {

    @DubboReference
    private QuestionService questionService;

    @DubboReference
    private NotificationService notificationService;

    //查看通用设置
    public ResponseEntity settings() {
        //获取线程内UserId
        User user = UserHolder.get();

        //查询默生人问题
        Question question = questionService.findById(user.getId());
        //查询通知设置
        Notification notification = notificationService.findById(user.getId());

        //封装SettingVo对象
        SettingVo vo = new SettingVo();
        vo.setId(user.getId());//设置id
        if (question != null){
            vo.setStrangerQuestion(question.getStrangerQuestion());//陌生人问题
        }
        if (notification != null){//系统通知
            vo.setLikeNotification(notification.getLikeNotification());
            vo.setPinglunNotification(notification.getPinglunNotification());
            vo.setGonggaoNotification(notification.getGonggaoNotification());
        }
        vo.setPhone(user.getMobile());//设置电话

        //返回前端结果
        return ResponseEntity.ok(vo);
    }


}
